package com.example.demo.service.impl;

import com.example.demo.mapper.StudentCertificationMapper;
import com.example.demo.mapper.entity.Student;
import com.example.demo.mapper.entity.StudentCertification;
import com.example.demo.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TestServiceImpl implements TestService {
    @Autowired
    private StudentCertificationMapper mapper;

    @Override
    public Student selectStudentById(int studentId) {
        return mapper.selectStudentById(studentId);
    }

    @Override
    public void placeBareheadedPhoto(StudentCertification bareheaded) {
        Student currentStudent=new Student();
        currentStudent.setNumber(bareheaded.getStudentNumber());
        currentStudent.setBareheadedPhoto(bareheaded.getBareheadedPhoto());

        int exist = mapper.selectByNumber(bareheaded.getStudentNumber());
        if(exist==0){  //在student_certification表中不存在
            bareheaded.setState(2);
            mapper.insertCertification(bareheaded);  //在student_certification表中插入數據
            mapper.updateBareheadedPhoto(currentStudent);  //在student表中更新數據
        }else{
            mapper.placeBareheadedPhoto(bareheaded);
            mapper.updateBareheadedPhoto(currentStudent);
        }
    }
}
